//////////////////////////////////////////////////////////////////////////////////////////////////////
//
// CocosJoy.h      
//
//				 -by Wander
//////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef COCOSJOYSTICK_H_20120203
#define COCOSJOYSTICK_H_20120203

#include "cocos2d.h"

const float JOY_MOVERAIDUS_MAX = 60;
class CCocosJoystick : public cocos2d::CCLayer
{
public:
	virtual void onEnter();
	virtual void onExit();

	virtual void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
	virtual void ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
	virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
	virtual void ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);

	bool IsContainsTouch(cocos2d::CCTouch *pTouch);

	LAYER_NODE_FUNC(CCocosJoystick);
public:
	CCocosJoystick();

	static CCocosJoystick *CreateJoystick(cocos2d::CCNode *pParent, int zOrder, const char *szJoyPath, const char *szJoybkPath, bool isCanMove,  cocos2d::CCRect rcCapture);
	void SetEnable(bool bEnable);
	void UpdateState(cocos2d::ccTime dt);

	float GetCurRotation() {return m_curRotation;}
	float GetCurPower()    {return m_curPower;}
	float GetCurPowerX()   {return m_curPowerX;}
	float GetCurPowerY()   {return m_curPowerY;}

private:
	void InitState(const char *szJoyPath, const char *szJoybkPath, bool isCanMove,  cocos2d::CCRect rcCapture);
private:
	cocos2d::CCSprite *m_pSprBack;
	cocos2d::CCSprite *m_pSprCenter;

	bool               m_bCanMove;
	cocos2d::CCRect    m_rcCapture;

	bool               m_bEnable;
	bool               m_bTouched;
	cocos2d::CCPoint   m_ptCenter;
	cocos2d::CCPoint   m_ptCur;
	cocos2d::CCTouch  *m_pCurTouch;

	float              m_curRotation;
	float              m_curPower;
	float              m_curPowerX;
	float              m_curPowerY;
};

#endif